package com.siwei.mes.controller.experiment;

import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.entity.ExperimentCheckRecord;
import com.siwei.mes.service.ExperimentCheckRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 试验台账检测记录相关
 *
 * @Description: 试验台账检测记录相关
 * @Version: 1.0
 * @author: chenmaolin
 * @date: 2024/1/6 20:48
 */
@Api(value = "试验台账检测记录相关")
@RestController
@RequestMapping("experimentCheckRecord")
public class ExperimentCheckRecordController {
    @Resource
    private ExperimentCheckRecordService experimentCheckRecordService;

    @ApiOperation(value = "根据试验台账id获取所有检测记录信息")
    @GetMapping("selectByExperimentId")
    public Json selectByExperimentId(@RequestParam("experimentId") Long experimentId) {
        return Json.succ().data(ApiResult.addList(experimentCheckRecordService.selectByExperimentId(experimentId)));
    }

    @ApiOperation(value = "修改检测记录")
    @PostMapping("/update")
    public Json update(@RequestBody ExperimentCheckRecord experimentCheckRecord) {
        assertTrue(experimentCheckRecord.getId() == null, "主键id为空");
        assertTrue(experimentCheckRecord.getExperimentId() == null, "试验台账id为空");
        assertTrue(experimentCheckRecord.getCheckType() == null, "检查类型为空");
        assertTrue(StringUtils.isBlank(experimentCheckRecord.getResultValue()), "检测值为空");
        experimentCheckRecordService.update(experimentCheckRecord);
        return Json.succ().data(new ApiResult());
    }
}
